func buildTree(inorder []int, postorder []int) *TreeNode {
    inorderIdxMap := map[int]int{}
    for i, v := range inorder {
        inorderIdxMap[v] = i
    }
    var build func(int, int) *TreeNode
    build = func(inorderLeft, inorderRight int) *TreeNode {
        if inorderLeft > inorderRight {
            return nil
        }

        val := postorder[len(postorder)-1]
        postorder = postorder[:len(postorder)-1]
        root := &TreeNode{Val: val}

        inorderRootIndex := inorderIdxMap[val]
        root.Right = build(inorderRootIndex+1, inorderRight)
        root.Left = build(inorderLeft, inorderRootIndex-1)
        return root
    }
    return build(0, len(inorder)-1)
}
